<template>
  <div class="" style="display: inline;">
    <el-tag style="margin-left: 10px;" v-for="standard in standardList" v-if="standard.propName===name && standard.resultType!=='0'" type="danger">
      <span v-if="standard.resultType==='1' || standard.resultType==='2' || standard.resultType==='3'||standard.resultType==='4'">
        {{ standard.propValueMin }}-{{ standard.propValueMax }}
      </span>
      <span v-if="standard.resultType==='5'">
        ＞{{ standard.propValueMin }}
      </span>
      <span v-if="standard.resultType==='6'">
        ≥{{ standard.propValueMin }}
      </span>
      <span v-if="standard.resultType==='7'">
        ＜{{ standard.propValueMax }}
      </span>
      <span v-if="standard.resultType==='7' || standard.resultType==='8'">
        ≤{{ standard.propValueMax }}
      </span>
    </el-tag>
  </div>
</template>

<script>
import {deleteAction, getAction} from '@/api/manage'

export default {
  name: "StandardResultTypeTag",
  dicts: ['factory_test_item'],
  components: {
  },
  props: {
    standardList: {
      type: Array,
      default: null,
    },
    name: {
      type: String,
      required: true
    },
  },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 检验标准表格数据
      dataList: [],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        goodsId: null,
        goodsName: null,
        goodsCode: null,
        goodsModel: null,
        testType: null,
        propName: null,
        propNameCh: null,
        propValueMax: null,
        propValueMin: null,
        orderByColumn:'createTime',
        isAsc:'desc'
      },
      url: {
        list: '/factoryTestStandard/factoryTestStandard/list',
        remove: '/factoryTestStandard/factoryTestStandard/',
        export: '/factoryTestStandard/factoryTestStandard/export',
      },
      tableMaxHeight: window.innerHeight - 320,
    };
  },
  created() {
    this.getList();
    window.addEventListener('resize', this.getTableHeight);
  },
  destroyed() {
    window.removeEventListener('resize', this.getTableHeight)
  },
  methods: {
    /** 查询检验标准列表 */
    getList() {
      this.loading = true;
      getAction(this.url.list, this.queryParams).then(response => {
        this.dataList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    getTableHeight() {
      this.tableHeight = window.innerHeight - 320
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.$refs.form.handleAdd();
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.$refs.form.handleUpdate(row);
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids;
      deleteAction(this.url.remove, ids).then(response => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {
      });
    },
    /** 导出按钮操作 */
    handleExport() {
      this.download(this.url.export, {
        ...this.queryParams
      }, `factoryTestStandard_${new Date().getTime()}.xlsx`)
    },
  }
};
</script>
